--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit d1e116683755533a532f94bed25d490e52e31eb0
Parents : c005017
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-04-13T18:29:51-05:00
feat(electron): improve ElectronUtils with file and directory handling methods, clipboard functionality, and notification support
Changes
Diff
diff --git a/meshchatx/src/frontend/js/ElectronUtils.js b/meshchatx/src/frontend/js/ElectronUtils.js
index 6b3e5fd7..4361e4ad 100644
--- a/meshchatx/src/frontend/js/ElectronUtils.js
+++ b/meshchatx/src/frontend/js/ElectronUtils.js
@@ -27,6 +27,98 @@ class ElectronUtils {
window.electron.showPathInFolder(path);
}
}
+
+ static async openPath(path) {
+ if (window.electron?.openPath) {
+ return await window.electron.openPath(path);
+ }
+ return null;
+ }
+
+ static async pickFile() {
+ if (window.electron?.pickFile) {
+ return await window.electron.pickFile();
+ }
+ return null;
+ }
+
+ static async pickDirectory() {
+ if (window.electron?.pickDirectory) {
+ return await window.electron.pickDirectory();
+ }
+ return null;
+ }
+
+ static async copyTextToClipboard(text) {
+ if (text == null || text === "") {
+ return false;
+ }
+ const s = String(text);
+ try {
+ if (navigator.clipboard?.writeText) {
+ await navigator.clipboard.writeText(s);
+ return true;
+ }
+ } catch {
+ // fall through to execCommand
+ }
+ try {
+ const ta = document.createElement("textarea");
+ ta.value = s;
+ ta.setAttribute("readonly", "");
+ ta.style.position = "fixed";
+ ta.style.left = "-9999px";
+ document.body.appendChild(ta);
+ ta.select();
+ const ok = document.execCommand("copy");
+ document.body.removeChild(ta);
+ return ok;
+ } catch {
+ return false;
+ }
+ }
+
+ static async revealPathInFolderOrCopy(path, onCopiedWeb) {
+ if (!path) {
+ return false;
+ }
+ if (ElectronUtils.isElectron()) {
+ ElectronUtils.showPathInFolder(path);
+ return true;
+ }
+ const ok = await ElectronUtils.copyTextToClipboard(path);
+ if (ok) {
+ if (typeof onCopiedWeb === "function") {
+ onCopiedWeb();
+ }
+ return true;
+ }
+ return false;
+ }
+
+ static async openDirectoryOrCopy(dirPath, onCopiedWeb) {
+ if (!dirPath) {
+ return false;
+ }
+ if (ElectronUtils.isElectron() && window.electron?.openPath) {
+ await window.electron.openPath(dirPath);
+ return true;
+ }
+ const ok = await ElectronUtils.copyTextToClipboard(dirPath);
+ if (ok) {
+ if (typeof onCopiedWeb === "function") {
+ onCopiedWeb();
+ }
+ return true;
+ }
+ return false;
+ }
+
+ static showNotification(title, body, silent = false) {
+ if (window.electron?.showNotification) {
+ window.electron.showNotification(title, body, silent);
+ }
+ }
}
export default ElectronUtils;
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────